<template>
  <div class="history troubleshoot">
    <ul>
      <li>
        <span>排查情况：</span>
        {{history.condition || '暂无数据'}}
      </li>
      <li>
        <span>处理结果：</span>
        {{caseTypes[history.caseType - 1] || '暂无数据'}}
      </li>
      <li>
        <span>监管状态：</span>
        {{history.controlStatus || '暂无数据'}}
      </li>
      <li v-if="fileList.length > 0 && history.attachmentPath" class="files">
        <span>排查文件：</span>
        <div class="flist">
          <a v-for="(list, ind) in  fileList" :key="ind" @click="getlist(list)">{{list.name}}</a>
        </div>
      </li>
      <li v-else-if="fileList.length > 0 && !history.attachmentPath" class="files">
        <span>排查文件：</span>
        <label v-for="(list, ind) in  fileList" :key="ind">{{list.name}}</label>
      </li>
      <li class="files" v-else>
        <span>排查文件：</span>
        暂无数据
      </li>
      <li v-if="history.riskreportPath">
        <span>风险报告：</span>
        <a @click="reportDownloads(history.riskreportPath)">
          {{history.riskreportPath}}
        </a>
      </li>
      <li v-else>
        <span>风险报告：</span>
        暂无数据
      </li>
      <li>
        <span>排查用户：</span>
        {{history.operator || '暂无数据'}}
      </li>
      <li>
        <span>排查时间：</span>
        {{history.startTime | dateFormat}}
      </li>
    </ul>
  </div>
</template>

<script>
import {
  management as api
} from '../../api'
export default {
  data() {
    return {
      history: {},
      entname: '',
      num: 0,
      fileList: [],
      caseTypes:['线上排查', '线下排查', '移交工商', '移交公安', '自行处置', '归档']
    }
  },
  methods: {
    getDetails() {
      let params = {
        id: this.id
      }
      api.getCaseProcessDetails(params).then(ret => {
        if (!ret.data) {
          return false
        }
        this.history = ret.data
        // console.log(ret.data)
        let name = ret.data.attachmentName
        let url = ret.data.attachmentPath
        if (name) {
          name = name.split(',')
          name.map(item => {
            if (item) {
              this.fileList.push({
                name:item
              })
            }
          })
          if (url) {
            url = url.split(',')
            let urls = []
            url.map(item => {
              if (item) {
                urls.push(item)
              }
            })
            this.fileList.map((item, ind) => {
              item.url = urls[ind]
            })
          }
          console.log(this.fileList)
        }
      }).catch(err => {
        console.log(err)
      })
    },
    getlist(list) {
      location.href = window.api_host + '/entDataUpload/downloadFile?uploadFileUrl=' + encodeURI(encodeURI(list.url))
    },
    // 下载报告
    reportDownloads(name) {
      this.$msgbox({
        title: '系统提示',
        message: '<span>由于文件过大导致下载时间过长，请耐心等待</span>',
        center: true,
        roundButton: true,
        customClass: 'messageBox',
        type: 'info',
        dangerouslyUseHTMLString: true,
        callback: () => {}
      })
      location.href = window.api_host + '/entListAndDetail/downloadRiskReport?riskReportPath=' + encodeURI(encodeURI(name))
    }
  },
  mounted() {
    this.entname = this.$route.query.name || ''
    this.id = this.$route.query.id || ''
    this.getDetails()
    // if (!this.$store.state.user.userInfo.token) {
    //   let data = this.$router.resolve({name:'login'})
    //   window.open(data.href)
    // }
  }
}
</script>

<style lang="scss" scoped>
.troubleshoot {
  padding: 5px 30px 15px 45px;
  height: auto;
  ul li {
    // height: 32px;
    height: auto;
    font-size: 14px;
    line-height: 32px;
    position: relative;
  }
  ul li span {
    display: inline-block;
    width: 85px;
    color: #a6a6a6;
  }
  .flist {
    display: inline-block;
    width: 1180px;
  }
  .files {
    label,
    a {
      margin-right: 15px;
    }
    a {
      color: #2f97ff;
      cursor: pointer;
    }
  }
}
</style>


// WEBPACK FOOTER //
// src/view/managements/history.vue